{block name=body}
<div class="form">
		<div class="form-group col-sm-12" style="border-right:none;">
		  <label for="terms" >选择学期: </label><br>
		  <select id="terms" name="terms[]" class="select-dropdown" ><optgroup label="{$termgroups[0].year}">
		  {assign var=year value=$termgroups[0].year}
		  {foreach $termgroups as $t}{if $year neq $t.year}{assign var=year value=$t.year}</optgroup><optgroup label="{$t.year}">{/if}<option {if $t.termcategory_id eq $sel_term_id && $t.year eq $sel_year}selected="selected"{/if} id="term{$t.termcategory_id}" value="{$t.termcategory_id}" data-year="{$t.year}" data-term="{$t.termcategory_id}" data-uri="?term={$t.termcategory_id}&year={$t.year}&json=1">{$t.termcategory_name}</option>{/foreach}
		  </optgroup></select>
		</div>
      <div class="row">
        <div class="col-sm-12">
		<a href="javascript:void(0);" onClick="window.location.href = $('#terms option:selected').attr('data-uri')" class="btn btn-info report-green">变更学期</a>
        </div>
      </div>
</div>
<div id="dashboard-body">
  {include file='dashboard/admin-dashboard-body.tpl'}
</div>

<!--Load the AJAX API-->
<script type="text/javascript" src="/admin/includes/js/jsapi.js"></script>
<script type="text/javascript">
//Load the Visualization API and the piechart package.
google.load('visualization', '1.0', { 'packages':['corechart'] });

// Set a callback to run when the Google Visualization API is loaded.
google.setOnLoadCallback(drawPaymentChart);
function drawPaymentChart() {
 
  // Create the data table.
  {if $enrolmentpiechartdata}
  var data = new google.visualization.DataTable();
  data.addColumn('string', 'Status');
  data.addColumn('number', 'Enrolments');
  data.addRows([{foreach from=$enrolmentpiechartdata key=myId item=val name=list}['{$val.label}', {$val.value}]{if not $smarty.foreach.list.last},{/if}{/foreach}
  ]);
  // Set chart options
  var options = { 'legend': { 'position': 'labeled' },
		  					 'pieSliceText':'value',
                 'width':500,
                 'height':300, 'pieStartAngle': 100, 
                 slices: { 
                	 {foreach from=$enrolmentpiechartdata key=myId item=val name=list}{$val.colourid}: { color: '{$val.colour}' }{if not $smarty.foreach.list.last},{/if}{/foreach}
                   }
  };

  // Instantiate and draw our chart, passing in some options.
  var chart = new google.visualization.PieChart(document.getElementById('payment_chart_div'));
  chart.draw(data, options); 
  {/if}
}

//Set a callback to run when the Google Visualization API is loaded.
google.setOnLoadCallback(drawBudgetChart);
function drawBudgetChart() {
 
  // Create the data table.
  {if $enrolmentpiechartdata}
  var data = new google.visualization.DataTable();
  data.addColumn('string', 'State');
  data.addColumn('number', '当前');
  data.addColumn('number', '以前');
  data.addColumn('number', '预算');
  data.addRows([
                {foreach from=$budgetchartdata key=myId item=val name=list}
                ['{$myId}', {$val.current}, {$val.previous}, {$val.budget}]{if not $smarty.foreach.list.last},{/if}
                {/foreach}
  ]);
  
  // Set chart options
  var options = { 
								  vAxis: { title: "城市/地区", titleTextStyle: { color: "black" } },
							    hAxis: { title: "报名人数", titleTextStyle: { color: "black" } },
                 'width':1000,
                 'height':300,
                 colors: [{foreach from=$budgetchartdata key=myId item=val name=list}'{$val.colour}'{if not $smarty.foreach.list.last},{/if}{/foreach},'#ffae00'] };

  // Instantiate and draw our chart, passing in some options.
  var chart = new google.visualization.BarChart(document.getElementById('budget_chart_div'));
  chart.draw(data, options); 
  {/if}
}


//Set a callback to run when the Google Visualization API is loaded.
  google.setOnLoadCallback(drawDailyChart);
  function drawDailyChart() {
   
    // Create the data table.
    {if $enrolmentpiechartdata}
    var data = new google.visualization.DataTable();
    data.addColumn('string', 'Day');
    data.addColumn('number', '今年');
    data.addColumn('number', '去年');

    data.addRows([
                  {foreach from=$dailychartdata key=myId item=val name=list}
                  ['{$myId}',{$val.current},{$val.previous}]{if not $smarty.foreach.list.last},{/if}
                  {/foreach}
    ]);
    
    // Set chart options
    var options = { 
                    vAxis: { title: "报名人数", titleTextStyle: { color: "black" } },
                    hAxis: { title: "过去90天", titleTextStyle: { color: "black" } },
                   'width':1000,
                   'height':300,
                   colors: ['#48ac29','#009bdb'] };

    // Instantiate and draw our chart, passing in some options.
    var chart = new google.visualization.LineChart(document.getElementById('daily_chart_div'));
    chart.draw(data, options); 
    {/if}
  }
  
  //Set a callback to run when the Google Visualization API is loaded.
    google.setOnLoadCallback(drawStateTermChart);
    function drawStateTermChart() {
     
      // Create the data table.
      {if $enrolmentpiechartdata}
      var data = new google.visualization.DataTable();
      data.addColumn('string', 'Term');
      {foreach from=$enrolmentstatetermchartdata[$enrolmentstatetermfirstkey] key=myId item=val name=list}
      data.addColumn('number', '{$val.term_region}');
      {/foreach}
      data.addRows([
                    {foreach from=$enrolmentstatetermchartdata key=myId item=val name=list}
                    ['{$myId}',{foreach from=$val key=myId2 item=val2 name=list2}{$val2.enrolment}{if not $smarty.foreach.list2.last},{/if}{/foreach} ]{if not $smarty.foreach.list.last},{/if}
                    {/foreach}
      ]);
      
      // Set chart options
      var options = { 
                      vAxis: { title: "报名人数", titleTextStyle: { color: "black" } },
                      hAxis: { title: "学期", titleTextStyle: { color: "black" } },
                     'width':1000,
                     'height':300,
                     colors: ['#48ac29','#009bdb','#f55d0f','#ffae00','#0bd0cd','#d6165e','#008081'] };

      // Instantiate and draw our chart, passing in some options.
      var chart = new google.visualization.ColumnChart(document.getElementById('state_term_chart_div'));
      chart.draw(data, options); 
      {/if}
    }

function loadDashboard(form) {
    $('body').css('cursor', 'wait');
    $('#dashboard-body').html('');
    var sel = $('#terms option:selected');
    $.ajax({
      type : "POST",
      url : $(sel).attr('data-uri'),
      cache : false,
      data : "termid="+$(sel).attr('data-termid')+"&year="+$(sel).attr('data-year'),
      dataType : "json",
      success : function(data, textStatus) {
        try {
          $('#dashboard-body').prepend(data['html']);
          eval(data['javascript']);
          $('body').css('cursor', 'default');
        } catch (err) {
          $('body').css('cursor', 'default');
        }
      }
    });
}
</script>

{/block} 



